package com.feicheng.controller;


import com.feicheng.base.result.Result;
import com.feicheng.entity.Warehouse;
import com.feicheng.model.UserAndWarehouse;
import com.feicheng.model.WarehouseInfo;
import com.feicheng.model.WarehouseWithStore;
import com.feicheng.service.ProviderWarehouseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hao.zhang
 * @since 2022-07-04
 */
@RestController
@RequestMapping("/warehouse")
public class WarehouseController {

    //依赖注入
    @Autowired
    ProviderWarehouseController providerWarehouseController;


    /**
     * 仓库列表条件分页接口
     * @author lu.yu
     * @param current  当前页数
     * @param size   每页条数
     * @param userAndWarehouse  返回的信息
     * @return
     */
        @GetMapping("/page")
    public Result get(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            UserAndWarehouse userAndWarehouse
    ){
        return providerWarehouseController
                .selectByPage(current, size,userAndWarehouse);
    }

    /**
     * 新增仓库接口
     * @param warehouseWithStore 仓库信息
     * @author zhengnan.fu
     * @return
     */
    @PostMapping("/info")
    public Result addWarehouse(@RequestBody WarehouseWithStore warehouseWithStore) {
        return providerWarehouseController.addWarehouse(warehouseWithStore);
    }

    /**
     * 仓库下拉查询
     *
     * @param storeId 门店编号
     * @author peiwen.song
     * @since 2022-07-05
     * @return
     */
    @GetMapping("/info/all/g")
    public Result selectWarehouse(
            Integer storeId
    ) {
        return Result.success(providerWarehouseController.selectWarehouse(storeId));
    }

    /**
     * 修改仓库信息接口
     * @param warehouseInfo 仓库信息
     * @author yu.xiu
     * @return
     */

    @PutMapping("/info")
    public Result updateinfo(@RequestBody WarehouseInfo warehouseInfo){
        return  Result.success(warehouseInfo.getWarehouseId());
    }

    /**
     * 根据仓库编号逻辑删除仓库信息接口
     * @param warehouse 仓库信息
     * @author yue.guo
     * @return true/false
     */

    @DeleteMapping("/info")
    public Result updateDflgByWarehouseId(@RequestBody Warehouse warehouse){
        return Result.success(providerWarehouseController.updateDflgByWarehouseId(warehouse));
    }

    /**
     * 仓库信息详细查询
     * @param warehouseId 仓库主键
     * @author bo.wei
     * @return
     */
    @GetMapping("/info/g")
    public Result selectWarehouseOne(Integer warehouseId){
        return providerWarehouseController.selectWarehouseOne(warehouseId);
    }

}


